package com.yngrp.util;

import java.text.ParseException;
import java.util.Calendar;
import java.util.List;


public class Constant {
	
	//办结
	public static final String S01 = "S01";
	//归档
	public static final String S00 = "S00";
	//提交审核
	public static final String S02 = "S02";
	//派发到部门
	public static final String S03 = "S03";
	//退单
	public static final String S04 = "S04";
	
	//增值服务
	public static final String A02 = "A02";
	
	//95598工单
	public static final String A01 = "A01";
	
	//坐席人员角色编码
	public static final String SEAT_ROLECODE = "searters";
	
	//优质管理人员角色编码
	public static final String SEAT_ROLE_MGR_CODE = "seatsmgr";
	
	//增值管理人员角色编码
    public static final String ZZ_ROLE_MGR_CODE = "zzmgr";
	
	//坐席管理人员角色编码
	public static final String MANAGER_ROLE_CODE = "manager";
	
	//班组管理员角色编码
	public static final String TEAM_ROLE_CODE = "teammgr";
	
	
	//工单类型编码
	public static final String WOTYPE = "woType";
	
	//工单状态编码
	public static final String WOSTATE = "woState";
	
	
	//电费查询任务状态—0：未完成
	public static final String AP_0_STATE = "0";
	
	//电费查询任务状态—0：未完成
	public static final String AP_0_STATE_DESC = "未完成";
	
	//电费查询任务状态—1：已完成
	public static final String AP_1_STATE = "1";
		
	//电费查询任务状态态—1：已完成
	public static final String AP_1_STATE_DESC = "已完成";

	//电费查询方式编码
	public static final String AP_QUERYMODE = "elecQuery";
	
	//集团启动状态字典编码
	public static final String GROUP_STATE = "groupState";
	
	//电费查询日期最大天数
	public static final int MAX_QUERY_DAY = 28;
	
	//电费查询月份格式化
	public static final String FORMART_QUERY_MONTH = "yyyy-MM";
	
	//电费查询日期格式化
    public static final String FORMART_QUERY_DAY = "yyyy-MM-dd";
    
	//手动电费查询生成方式
    public static final String MANUAL_CREATE_MODE = "手动生成";
    
	//自动动电费查询生成方式
    public static final String AUTO_CREATE_MODE = "自动生成";
    
	//双月
    public static final String EVEN_MONTH = "02";
    
    //单月
    public static final String ODD_MONTH = "01";
    
    //每月
    public static final String EVERY_MONTH = "00";
    
    //执行成功
    public static final String SUCCESS = "success";
    
    //执行失败
    public static final String ERROR = "error";
    
    //无可生成查询的集团
    public static final String NONE = "none";
    
    //默认用户访问的首页URL
    public static final String DEFAULT_HOMEPAGE_URL = "loginController.do?acehome";
    
	//集团启用状态编码
	public static final String GROUP_ENABLE_STATE = "1";
	
	//集团激活状态字典编码
	public static final String GROUP_ACTIVE_STATE = "group_active_state";
	
	//集团激活状态字典编码项
	public static final String GROUP_ENABLE_ACTIVE_STATE = "1";
	
	//集团锁定状态字典编码项
	public static final String GROUP_DISABLE_ACTIVE_STATE = "0";
	
	//工单办结时间类型 *天
	public static final String OVERTIME_TYPE_DAY = "day";
	
	//工单办结时间类型 *小时 
	public static final String OVERTIME_TYPE_HOUR = "hour";
	
	//工单办结时间格式化
    public static final String OVERTIME_DATE_FMT = "yyyy-MM-dd HH:mm:ss";
    
    //服务平台
    public static final String PLATFROM_SERVICE = "服务平台";
    
    //95598
    public static final String PLATFROM_95598 = "95598";
    
     //未读工单
  	public static final String WO_ISREAD_0 = "未读";
  	
  	 //已读工单
  	public static final String WO_ISREAD_1 = "已读";
    
    /**  
     *   
     * <p>Title: checkHoliday </P>  
     * <p>Description: TODO 验证日期是否是节假日</P>  
     * @param calendar  传入需要验证的日期  
     * @param holidayList  节假日集合
     * @return   
     * return boolean    返回类型  返回true是节假日，返回false不是节假日  
     * throws   
     * date 2016-09-25 下午22:13:07  
     */  
    public static boolean checkHoliday(Calendar calendar,List<Calendar> holidayList) throws Exception{  
          
        //判断日期是否是周六周日  
        if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||   
                calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY){  
            return true;  
        }  
        //判断日期是否是节假日  
        for (Calendar ca : holidayList) {  
           if(ca.get(Calendar.MONTH) == calendar.get(Calendar.MONTH) &&  
                   ca.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)&&  
                   ca.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)){  
               return true;  
           }  
       }  
           
        return false;  
    }  
    
    /**  
     *   
     * <p>Title: initHolidayList </P>  
     * <p>Description: TODO  把所有节假日放入list</P>  
     * @param date  从数据库查 查出来的格式2014-05-09  
     * @param holidayList  节假日集合
     * return void    返回类型   
     * throws   
     * date 2016-09-25 下午22:13:07  
     */  
   public static void addHolidayList( String date,List<Calendar> holidayList){  
         
           String [] da = date.split("-");  
             
           Calendar calendar = Calendar.getInstance();  
           calendar.set(Calendar.YEAR, Integer.valueOf(da[0]));  
           calendar.set(Calendar.MONTH, Integer.valueOf(da[1])-1);//月份比正常小1,0代表一月  
           calendar.set(Calendar.DAY_OF_MONTH, Integer.valueOf(da[2]));  
           holidayList.add(calendar);  
   } 
   
   /**  
    *   
    * <p>Title: addDateByWorkDay </P>  
    * <p>Description: TODO  计算相加day天，并且排除节假日和周末后的日期</P>  
    * @param calendar  当前的日期  
    * @param day  相加天数  
    * @param holidayList  节假日集合
    * @return     
    * return Calendar    返回类型   返回相加day天，并且排除节假日和周末后的日期  
    * throws   
    * date 2016-09-25 下午22:13:07 
    */  
   public static Calendar addDateByWorkDay(Calendar calendar,int day,List<Calendar> holidayList){  
         
       try {  
    	   //判断是否节假日	
           if(checkHoliday(calendar,holidayList)){   
        	   while(true){
        		   calendar.add(Calendar.DAY_OF_MONTH, 1); 
        		   if(!checkHoliday(calendar,holidayList)){
        			   break;
        		   }
        	   }
        	   
        	   calendar.set(Calendar.HOUR_OF_DAY, 8);
        	   calendar.set(Calendar.MINUTE, 30);
        	   calendar.set(Calendar.SECOND, 0);
           }
           
          for (int i = 0; i < day; i++) {  
                
               calendar.add(Calendar.DAY_OF_MONTH, 1);  
                 
               if(checkHoliday(calendar,holidayList)){  
                   i--;  
               }  
          }  
          return calendar;              
         
      } catch (Exception e) {  
          e.printStackTrace();  
      }  
      return calendar;  
   }  
   
   
   
   /**  
    *   
    * <p>Title: addHourByWorkHour </P>  
    * <p>Description: TODO  计算相加hour小时，并且排除节假日和周末后的时间</P>  
    * @param calendar  当前的日期  
    * @param hour  相加小时  
    * @param holidayList  节假日集合
    * @return     
    * return Calendar    返回类型   返回相加hour小时，并且排除节假日和周末后的时间  
    * throws   
    * date 2016-09-25 下午22:13:07 
    */  
   public static Calendar addHourByWorkHour(Calendar calendar,int hour,List<Calendar> holidayList){  
         
       try {  
            //判断是否节假日	
           if(checkHoliday(calendar,holidayList)){   
        	   while(true){
        		   calendar.add(Calendar.DAY_OF_MONTH, 1); 
        		   if(!checkHoliday(calendar,holidayList)){
        			   break;
        		   }
        	   }
        	   
        	   calendar.set(Calendar.HOUR_OF_DAY, 8);
        	   calendar.set(Calendar.MINUTE, 30);
        	   calendar.set(Calendar.SECOND, 0);
           }

           for (int i = 0; i < hour; i++) {  
              
              calendar.add(Calendar.HOUR_OF_DAY, 1);  
                
              if(checkHour(calendar))  {
           	     i--;  
              }
           } 
          
		   return calendar;             
         
      } catch (Exception e) {  
          e.printStackTrace();  
      }  
      return calendar;  
   }  
   
   //判断是否工作时间 
   public static boolean checkHour(Calendar calendar) throws Exception{  
       
       if(calendar.get(Calendar.HOUR_OF_DAY) <9){  
           return true;  
       }  
       
       if(calendar.get(Calendar.HOUR_OF_DAY) >16){  
           return true;  
       }          
          
       return false;  
   } 

   //日期相减得到天数
   public static  long getDaySub(String beginDateStr,String endDateStr){
	   long day=0;
       java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");   
       java.util.Date beginDate;
       java.util.Date endDate;
       try
       {
           beginDate = format.parse(beginDateStr);
           endDate= format.parse(endDateStr);   
           day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);   
           //System.out.println("相隔的天数="+day);  
       } catch (ParseException e)
       {
           // TODO 自动生成 catch 块
           e.printStackTrace();
       }  
       return day;
	}
}
